package com.yy.aspect;

import base.Result;
import enums.ResponseEnum;
import exception.TokenException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常
 * @author lyy
 * @date 2021/12/13
 */
@Slf4j
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(TokenException.class)
    public Result tokenExceptionHandler(TokenException e){
        log.error("token异常：【{}】", e.getMessage(), e);
        return Result.error(ResponseEnum.TOKEN_EXCEPTION);
    }

    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e){
            log.error("全局异常：【{}】",e.getMessage(), e);
        return Result.error(ResponseEnum.SYSTEM_ERROR);
    }

}
